package com.hyg.base.ui.adapter;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import com.hyg.base.ui.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * @author huangyuguang
 * @description: 首页页签的adapter
 * @date 2017/6/12  21:36
 */

public class MainTabAdapter extends SmartFragmentStatePagerAdapter {

    private String[] titleStrings;

    private List<BaseFragment> mFragments = new ArrayList<BaseFragment>();

    public MainTabAdapter(List<BaseFragment>fragmentList, FragmentManager fm) {
        this(fragmentList,null,fm);
    }
    public MainTabAdapter(List<BaseFragment>fragmentList, String[] titleStrings, FragmentManager fm) {
        super(fm);
        if (fragmentList != null){
            mFragments = fragmentList;
        }
        this.titleStrings = titleStrings;
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

    @Override
    public int getCount() {
        return mFragments.size();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return titleStrings[position];
    }
}
